package com.base.taskreports.task.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.base.taskreports.common.annotation.TBatchLog;
import com.base.taskreports.reports.entiyt.jfs.TblChaccCommPriAcctInfEntity;
import com.base.taskreports.reports.entiyt.jfs.TblCqpntPointInFlowEntity;
import com.base.taskreports.reports.entiyt.jfs.TblPointActivityEntity;
import com.base.taskreports.reports.entiyt.master.TIndicatorsEntity;
import com.base.taskreports.reports.service.TIndicatorsService;
import com.base.taskreports.reports.service.TblChaccCommPriAcctInfService;
import com.base.taskreports.reports.service.TblCqpntPointInFlowService;
import com.base.taskreports.reports.service.TblPointActivityService;
import com.base.taskreports.task.service.JfsService;

//import net.sf.json.JSONObject;
@Service("jfsService")
public class JfsServiceImpl implements JfsService {
	
	@Autowired
	private TblCqpntPointInFlowService tblCqpntPointInFlowService;
	
	
	@Autowired
	private TIndicatorsService tIndicatorsService;
	
	
	@Autowired
	private TblPointActivityService tblPointActivityService;
	
	
	@Autowired
	private TblChaccCommPriAcctInfService  tblChaccCommPriAcctInfService;


	//非货币积分发放金额浮动比率
	@Override
	@TBatchLog("JFS_M001")
	public void getJFS_M001(String DateTime) {
		//查询积分送 指标值   JFS	积分-送分 JFS_M001 非货币积分发放金额浮动比率
		List<TblCqpntPointInFlowEntity> selectFloatingRateOfNonMonetaryPoints = tblCqpntPointInFlowService.selectFloatingRateOfNonMonetaryPoints(DateTime);
		if(selectFloatingRateOfNonMonetaryPoints != null && selectFloatingRateOfNonMonetaryPoints.size()>0) {
			for (TblCqpntPointInFlowEntity tblCqpntPointInFlowEntity : selectFloatingRateOfNonMonetaryPoints) {
				//插入指标表
				TIndicatorsEntity tIndicatorsEntity = new TIndicatorsEntity();
				tIndicatorsEntity.setIndicatorCode("JFS_M001");
				tIndicatorsEntity.setIndicatorValue(tblCqpntPointInFlowEntity.getToday()!= null? tblCqpntPointInFlowEntity.getToday().toString():"0");
				tIndicatorsService.saveTIndicators(tIndicatorsEntity);
			}
		}
	}
	// 非人民币货币积分发放金额浮动比率
	@Override
	@TBatchLog("JFS_M002")
	public void getJFS_M002(String DateTime) {
		//非人民币货币积分配置表 獲取Id
		List<TblPointActivityEntity> TblPointActivityList = tblPointActivityService.selectFloatingRatioOfNonRMBCurrencyPoints(DateTime);
			
		// 根据id号查询非人民币货币积分发放金额
		 List<TblCqpntPointInFlowEntity> selectFloatingRatioOfNonRMBCurrencyPoints = tblCqpntPointInFlowService.selectFloatingRatioOfNonRMBCurrencyPoints(DateTime,TblPointActivityList);
		//插入指标表
		 if(selectFloatingRatioOfNonRMBCurrencyPoints != null && selectFloatingRatioOfNonRMBCurrencyPoints.size()>0) {
				for (TblCqpntPointInFlowEntity tblCqpntPointInFlowEntity : selectFloatingRatioOfNonRMBCurrencyPoints) {
					TIndicatorsEntity tIndicatorsEntity = new TIndicatorsEntity();
					tIndicatorsEntity.setIndicatorCode("JFS_M002");
					tIndicatorsEntity.setIndicatorValue(tblCqpntPointInFlowEntity.getToday()!= null? tblCqpntPointInFlowEntity.getToday().toString():"0");
					tIndicatorsService.saveTIndicators(tIndicatorsEntity);
				 }
		   }		
	}
	// 事后结算积分发放金额浮动比率
	@Override
	@TBatchLog("JFS_M003")
	public void getJFS_M003(String DateTime) {
		//事后结算积分发放金额浮动比率 獲取Id
		List<TblPointActivityEntity> TblPointActivityList = tblPointActivityService.selectFloatingRatioOfBonusAmountIssuedAfterSettlement(DateTime);
		//查询积分送 指标值   JFS	积分-送分 JFS_M001 非货币积分发放金额浮动比率
		List<TblCqpntPointInFlowEntity> selectFloatingRateOfNonMonetaryPoints = tblCqpntPointInFlowService.selectFloatingRatioOfBonusAmountIssuedAfterSettlement(DateTime,TblPointActivityList);
		if(selectFloatingRateOfNonMonetaryPoints != null && selectFloatingRateOfNonMonetaryPoints.size()>0) {
			for (TblCqpntPointInFlowEntity tblCqpntPointInFlowEntity : selectFloatingRateOfNonMonetaryPoints) {
				//插入指标表
				TIndicatorsEntity tIndicatorsEntity = new TIndicatorsEntity();
				tIndicatorsEntity.setIndicatorCode("JFS_M003");
				tIndicatorsEntity.setIndicatorValue(tblCqpntPointInFlowEntity.getToday()!= null? tblCqpntPointInFlowEntity.getToday().toString():"0");
				//tIndicatorsEntity.setParameter1(tblCqpntPointInFlowEntity.getRemark()!= null? tblCqpntPointInFlowEntity.getRemark().toString():"0");
				tIndicatorsService.saveTIndicators(tIndicatorsEntity);
			}
		}
		
	}
	 // 单用户货币积分余额> N浮动比率
	@Override
	@TBatchLog("JFS_M004")
	public void getJFS_M004(String DateTime) {
		//查询单用户货币积分名单
		List<TblCqpntPointInFlowEntity> selectFloatingRateOfNonMonetaryPoints = tblCqpntPointInFlowService.selectSingleUserCurrencyScoreBalanceNFloatingRatio(DateTime);
		//根据名单查询金额
		List<TblChaccCommPriAcctInfEntity> selectSingleUserCurrency = tblChaccCommPriAcctInfService.selectSingleUserCurrency(selectFloatingRateOfNonMonetaryPoints);
		if(selectSingleUserCurrency != null && selectSingleUserCurrency.size()>0) {
			for (TblChaccCommPriAcctInfEntity tblChaccCommPriAcctInfEntity : selectSingleUserCurrency) {
				//插入指标表
				TIndicatorsEntity tIndicatorsEntity = new TIndicatorsEntity();
				tIndicatorsEntity.setIndicatorCode("JFS_M004");
				tIndicatorsEntity.setIndicatorValue(tblChaccCommPriAcctInfEntity.getAvlBalance()!= null? tblChaccCommPriAcctInfEntity.getAvlBalance().toString():"0");
				tIndicatorsService.saveTIndicators(tIndicatorsEntity);
			}
		}
		
	}
	// 单用户非货币积分余额> N浮动比率
	@Override
	@TBatchLog("JFS_M005")
	public void getJFS_M005(String DateTime) {
		//查询积分送 指标值   JFS	积分-送分 JFS_M001 非货币积分发放金额浮动比率
		List<TblCqpntPointInFlowEntity> selectFloatingRateOfNonMonetaryPoints = tblCqpntPointInFlowService.selectSingleUserNonCurrencyPointsBalanceNFloatingRatio(DateTime);
		//根据名单查询金额
		List<TblChaccCommPriAcctInfEntity> selectSingleUserCurrency = tblChaccCommPriAcctInfService.selectSingleUserCurrency(selectFloatingRateOfNonMonetaryPoints);
		if(selectSingleUserCurrency != null && selectSingleUserCurrency.size()>0) {
			for (TblChaccCommPriAcctInfEntity tblChaccCommPriAcctInfEntity : selectSingleUserCurrency) {
				//插入指标表
				TIndicatorsEntity tIndicatorsEntity = new TIndicatorsEntity();
				tIndicatorsEntity.setIndicatorCode("JFS_M005");
				tIndicatorsEntity.setIndicatorValue(tblChaccCommPriAcctInfEntity.getAvlBalance()!= null? tblChaccCommPriAcctInfEntity.getAvlBalance().toString():"0");
				tIndicatorsService.saveTIndicators(tIndicatorsEntity);
			}
		}
		
	}
	// 临时用户（非注册用户,即不使用userID用户）交易数量浮动比	
	@Override
	@TBatchLog("JFS_M006")
	public void getJFS_M006(String DateTime) {
		//查询积分送 指标值  临时用户（非注册用户,即不使用userID用户）交易数量浮动比	
		List<TblCqpntPointInFlowEntity> selectFloatingRateOfNonMonetaryPoints = tblCqpntPointInFlowService.selectFloatingRatioOfTheNumberOfTransactionsByTemporaryUsers(DateTime);
		if(selectFloatingRateOfNonMonetaryPoints != null && selectFloatingRateOfNonMonetaryPoints.size()>0) {
			for (TblCqpntPointInFlowEntity tblCqpntPointInFlowEntity : selectFloatingRateOfNonMonetaryPoints) {
				//插入指标表
				TIndicatorsEntity tIndicatorsEntity = new TIndicatorsEntity();
				tIndicatorsEntity.setIndicatorCode("JFS_M006");
				tIndicatorsEntity.setIndicatorValue(tblCqpntPointInFlowEntity.getToday()!= null? tblCqpntPointInFlowEntity.getToday().toString():"0");
				tIndicatorsService.saveTIndicators(tIndicatorsEntity);
			}
		}
				
		
	}
	 // 积分余额为负数量	
	@Override
	@TBatchLog("JFS_M007")
	public void getJFS_M007(String DateTime) {
		Integer  selectFloatingRateOfNonMonetaryPoints = tblChaccCommPriAcctInfService.countTblCqpntPointInFlow(DateTime);
		//插入指标表
		TIndicatorsEntity tIndicatorsEntity = new TIndicatorsEntity();
		tIndicatorsEntity.setIndicatorCode("JFS_M007");
		tIndicatorsEntity.setIndicatorValue(selectFloatingRateOfNonMonetaryPoints != null? selectFloatingRateOfNonMonetaryPoints.toString():"0");
		tIndicatorsService.saveTIndicators(tIndicatorsEntity);
		
	}



		
	  // 单用户货币积分余额> N浮动比率y  //前50笔详情
	@Override
	public List<Object> getJFS_M004_Detail(String DateTime) {
		// TODO Auto-generated method stub
		//查询单用户货币积分名单
		List<Object> arrayList = new ArrayList<Object>();
		List<TblCqpntPointInFlowEntity> selectFloatingRateOfNonMonetaryPoints = tblCqpntPointInFlowService.selectSingleUserCurrencyScoreBalanceNFloatingRatio(DateTime);
		//根据名单查询金额
		List<TblChaccCommPriAcctInfEntity> selectSingleUserCurrency = tblChaccCommPriAcctInfService.selectTheTopFiftySingleUserCurrencyScoreBalanceNFloatingRatio(selectFloatingRateOfNonMonetaryPoints);
		this.setObjectList(selectSingleUserCurrency,arrayList);
    	return arrayList;
	}
	 // 单用户非货币积分余额> N浮动比率y  //前50笔详情
	@Override
	public List<Object> getJFS_M005_Detail(String DateTime) {
		List<Object> arrayList = new ArrayList<Object>();
		//查询积分送 指标值   非货币积分发放金额浮动比率
		List<TblCqpntPointInFlowEntity> selectFloatingRateOfNonMonetaryPoints = tblCqpntPointInFlowService.selectSingleUserNonCurrencyPointsBalanceNFloatingRatio(DateTime);
		//根据名单查询金额
		List<TblChaccCommPriAcctInfEntity> selectSingleUserCurrency = tblChaccCommPriAcctInfService.selectTheTopFiftySingleUserNonCurrencyPointsBalanceNFloatingRatio(selectFloatingRateOfNonMonetaryPoints);
		this.setObjectList(selectSingleUserCurrency,arrayList);
   		return arrayList;
	}
	 // 积分余额为负数量			y	 //前50笔详情
	@Override
	public List<Object> getJFS_M007_Detail(String DateTime) {
		List<Object> arrayList = new ArrayList<Object>();
		// TODO Auto-generated method stub
	 	List<TblChaccCommPriAcctInfEntity> selectSingleUserCurrency =  tblChaccCommPriAcctInfService.selectTheTopFiftyTheCreditBalanceNegativeQuantity(DateTime);
	 	this.setObjectList(selectSingleUserCurrency,arrayList);
		return arrayList;
	}

	
	public void setObjectList(List<TblChaccCommPriAcctInfEntity> selectSingleUserCurrency,List<Object> arrayList){
		for (TblChaccCommPriAcctInfEntity tblChaccCommPriAcctInfEntity : selectSingleUserCurrency) {
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getSeqId());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getAcctCd());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getAccessId());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getAcctTp());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getAcctTpId());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getAcctEntityTp());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getAcctEntityId());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getAvlBalance());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getFrozenBalance());
	   		   
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getOperBalance());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getExpireBalance());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getTodeductBalance());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getExpireIn());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getLastBeginBal());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getLastDate());

	   		   
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getAcctSt());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getAcctOpenTp());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getAcctOpenTm());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getAcctCloseTm());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getReservedField());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getRecCrtTs());

	   		   
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getRecUpdTs());
	   		   arrayList.add(tblChaccCommPriAcctInfEntity.getVersion());

	
		}
	}


	
}
